<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html class="win-frame">
<head>
<title>${name_china}管理-编辑${name_china}</title>
<%@include file="/common/head.jsp" %>
<link href="<%=request.getContextPath()%>/static/styles/css/main.css" rel="stylesheet">
<script src="<%=request.getContextPath()%>/static/js/jquery.cityselect.js"></script>
</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
            <span class="split"></span>
            <span>编辑${name_china}</span>
        </div>
        <a id="goBack" class="btn-return distance-left" href="javascript:;"><i class="icon icon-arrow-left"></i>返回上级</a>
    </div>
    <div class="page-title-border"></div>
</div>

<form id="form" method="post">
    <div class="form-wrapper">
	  <div class="h4 distance-double">
        <span class="h4-title"><i class="icon icon-setting"></i>基本信息</span>
        <span class="h4-border"></span>
        
      </div>
			<div class="form-cont">
			<p class="form-cont-title">商品名称:</p>${goodsName}
			 
			</div>
			
			<div class="form-cont" id="spuProperty">
			</div>
			
			<div id="city_4" class="form-cont">
				<p class="form-cont-title">所在地区：</p>
				<select class="prov" id="sel1" name="sel1" style="border: solid 1px #eee"></select>
				<select class="city" id="sel2" name="sel2" style="border: solid 1px #eee" disabled="disabled"></select>
				<select class="dist" id="sel3" name="sel3" style="border: solid 1px #eee" disabled="disabled"></select>
			</div>

			<div class="form-cont">
				<p class="form-cont-title">详细地址</p>
				<textarea class="summer-textarea" id="detail" name="detail"></textarea>
			</div>

			<div class="form-cont">
				<p class="form-cont-title">联系电话</p>
				<input type="text" id="receiverPhone" name="receiverPhone" class="summer-input summer-validatebox" data-validatebox="validType:['maxLength[11]']" />
			</div>
			
			<div class="form-cont">
				<p class="form-cont-title">收货人姓名</p>
				<input type="text" id="receiverName" name="receiverName" class="summer-input summer-validatebox" data-validatebox="validType:['maxLength[255]']" />
			</div>
			
	    
     <div class="form-btn-wrapper" id="funcbar">
     	<a class="btn btn-normal" id="saveBtn">保存</a>
        <a class="btn btn-normal" id="backBtn">关闭</a>
    </div>
  </div>
</form>
<script>
    
  var   propertyList,
  		goodsName,
  		name,
  		editData,
        permission = CommonUtil.getPermission('${name_english}');
    
    $(function () {
    	editData = ${editData};
    	 var allHTML = null;
    	for(var i=0;i<editData.length;i++){
    		name = editData[i].name;
    		var html = null;
    		for(var j=0;j<editData[i].list.length;j++){
    			if(html == null){
    				html = name+':<input type="radio" id="para'+i+'" name="para'+i+'" value="'+editData[i].list[j].id+'">'+editData[i].list[j].value+"&nbsp&nbsp&nbsp&nbsp";
    			}else{
    				html = html + '<input type="radio" id="para'+i+'" name="para'+i+'" value="'+editData[i].list[j].id+'">'+editData[i].list[j].value+"&nbsp&nbsp&nbsp&nbsp";
    			}
    		}
    		if(allHTML == null){
    			allHTML = html+"<br/> ";
    		}else{
    			allHTML = allHTML + html+"<br/> ";
    		}
    	}
		$("#spuProperty").append(allHTML);
    	 $("#city_4").citySelect({
 			prov:"湖南", 
 			city:"长沙",
 			dist:"岳麓区",
 			nodata:"none"
 		});
     	 
     	 $('#form').form({
        	onLoadSuccess:function(data){
               
           }
        }).form('loadDataEdit', {
            data: editData
        });
    	//保存按钮
    	$('#saveBtn').on('click',submit);
    	//返回按钮
    	$('#backBtn, #goBack').on('click',backMain);
    });
    
    
    
    //表单提交
    function submit() {
    	var skuParam = null;
    	for(var i=0;i<editData.length;i++){
    		var val = null;
    		val = $("input[name='para"+i+"']:checked").val();
        	if(skuParam == null){
        		skuParam = val;
        	}else{
        		skuParam = skuParam +":"+val;
        	}
    	}
    	var val1 = $("#sel1").val();
    	var val2 = $("#sel2").val();
    	var val3 = $("#sel3").val();
    	var userId = ${userId};
    	var spuId = ${spuId};
    	var id = ${id};
    	if(val3 == null){
    		city = val1 + val2;
    	}else{
    		city = val1 + val2 +val3;
    	}
         $("#form").form({
             ajax: {
                 url: CONST_URL.EDIT+"?city="+city+"&skuParam="+skuParam+"&userId="+userId+""+"&spuId="+spuId+""+"&id="+id+""
             },
             onSubmitSuccess: function (data) {
            	 $.stip({
   	                type:'ok',//显示类型 有info、 ok、 danger
   	                text: '保存成功！',
   	                onBeforeHide: function () {
   	                	backMain();
   	                }
            	 });
              }
         }).form("submit");
    }
    
    //返回主页面
    function backMain() {
    	window.location.href = CONST_URL.INIT_MAIN;
    }
    
    //请求url
    var CONST_URL = {
    	INIT_MAIN: basePath + "${common_url}init",
       	EDIT: basePath + "${common_url}edit"
    };
    
</script>
</body>
</html>